<template>
    <div class="mainTabs">
        <div class="left">
            <span>{{ unFinishedItems }} items left</span>
        </div>
        <div class="center">
            <span 
                v-for ="state in states" 
                :key="state"
                :class="[state, filter === state ? 'actived' : '']"
                @click="toggleFilter(state)"
            >
                {{ state }} 
            </span>
        </div>
        <div class="right">
            <button @click="clearCompleted">clear Completed</button>
        </div>
    </div>
</template>
<script>
export default {
    props:{
        filter:{
            type:String,
            required:true
        },             
        todos:{
            type:Array,
            required:true
        }
    },
    data(){
        return {
            states:['all', 'active', 'completed']
        }
    },
    computed:{
        unFinishedItems(){
            return this.todos.filter(todo => todo.completed == false).length;
        }
    },
    methods:{
        toggleFilter(state) {
            this.$emit('toggle',state);
        },
        clearCompleted() {
            this.$emit('clearCompletedTodos');
        }
    },
}
</script>
<style lang="scss" scoped>
    .mainTabs{
        display: flex;
        width: 80%;
        background-color: #fff;
        justify-content: space-between;
        padding: 0 20px;
        color: #555;    
        padding-top: 20px;
    }
    .mainTabs .center span {
        cursor: pointer;
        margin: 0 5px;
        padding: 0 2px;
    }
    .mainTabs .center span.actived {
        border: 1px red solid;
    }
    .mainTabs .right button {
        line-height: 2;
        border: 0;
        background: 0;
        color: #555;
    }
    .mainTabs .right button:focus{
        border: 0;
        outline: 0;
    }
    .mainTabs .right button:active{
        outline: 1px solid red;
    }
    .mainTabs .right button:hover{
        cursor: pointer;
    }
</style>
